
********************************
********* DiD - Labor **********
********************************

*** Set Fixed Effects and Clustering
global fe "caseid time"
global clusvar "partyr caseid"

capture frame drop SymDiDLabor
frame create SymDiDLabor str35 spec str35 outcome str35 group str32 time str32 refperiod  beta se N persons

foreach g in all female black notblack male {
foreach out in earnings employed {

** Symmetric 1-4
reghdfe `out'  evictionorderq24 evictionorderq23 evictionorderq22 evictionorderq21 evictionorderq20 evictionorderq19 evictionorderq18 evictionorderq17 evictionorderq16 evictionorderq15 evictionorderq14 evictionorderq13 evictionorderq12 evictionorderq11 evictionorderq10 evictionorderq9 evictionorderq8 evictionorderq7 evictionorderq6 evictionorderq5 q1q4evictionorder evictionorderq0 levictionorderq5 levictionorderq6 levictionorderq7 levictionorderq8 levictionorderq9 levictionorderq10 levictionorderq11 levictionorderq12 levictionorderq13 levictionorderq14 levictionorderq15 levictionorderq16 q24 q23 q22 q21 q20 q19 q18 q17 q16 q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q1q4 q0 lq1q4 lq5 lq6 lq7 lq8 lq9 lq10 lq11 lq12  lq13 lq14 lq15 lq16  if (index>=-16 & index<=24 ) & sentDOL==1 & ivsample==1 & `g'==1, absorb($fe) cluster($clusvar)

	capture frame post SymDiDLabor ("symDiD") ("`out'") ("`g'") ("Q01Q04") ("-16") (_b[q1q4evictionorder]) (_se[q1q4evictionorder]) (e(N)) (e(df_a))

** Symmetric 5-8
reghdfe `out'  evictionorderq24 evictionorderq23 evictionorderq22 evictionorderq21 evictionorderq20 evictionorderq19 evictionorderq18 evictionorderq17 evictionorderq16 evictionorderq15 evictionorderq14 evictionorderq13 evictionorderq12 evictionorderq11 evictionorderq10 evictionorderq9  q5q8evictionorder evictionorderq4 evictionorderq3 evictionorderq2 evictionorderq1 evictionorderq0 levictionorderq1 levictionorderq2 levictionorderq3 levictionorderq4 levictionorderq9 levictionorderq10 levictionorderq11 levictionorderq12 levictionorderq13 levictionorderq14 levictionorderq15 levictionorderq16 q24 q23 q22 q21 q20 q19 q18 q17 q16 q15 q14 q13 q12 q11 q10 q9 q5q8 q4 q3 q2 q1 lq1 lq2 lq3 lq4 lq5q8 lq9 lq10 lq11 lq12  lq13 lq14 lq15 lq16  if (index>=-16 & index<=24 ) & sentDOL==1 & ivsample==1 & `g'==1, absorb($fe) cluster($clusvar)
	
	capture frame post SymDiDLabor ("symDiD") ("`out'") ("`g'") ("Q05Q08") ("-16") (_b[q5q8evictionorder]) (_se[q5q8evictionorder]) (e(N)) (e(df_a))
	
}
}

frame SymDiDLabor: save "${Inputs}/NY_labor_did.dta", replace



********************************
******* DiD - Homeless *********
********************************

*** Set Fixed Effects and Clustering
global fe "caseid yearsince year"
global clusvar "partyr caseid"

capture frame drop homelessDiDannual
frame create homelessDiDannual str35 spec str55 outcome str32 group str32 time beta se persons N 

foreach g in all black female notblack male {
foreach o in apphomeless shelter {
			
		reghdfe `o' evictionorder6 evictionorder5 evictionorder4 evictionorder3 evictionorder2 evictionorder1 evictionorder0  levictionorder2 levictionorder3 levictionorder4  if all==1 & ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)
	frame post homelessDiDannual ("DiD") ("`o'") ("`g'") ("Q01Q04")  (_b[evictionorder1]) (_se[evictionorder1]) (e(df_a_nested)) (e(N))

		reghdfe `o' evictionorder6 evictionorder5 evictionorder4 evictionordery2t3 evictionorder1 evictionorder0 levictionorder1   levictionorder4  if all==1 & ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)

	sum `o' if evictionorder==0 & e(sample)==1 & yearsince==1
	capture frame post homelessDiDannual ("DiD") ("`o'") ("`g'")  ("Q01Q04") (`=r(mean)') (`=r(sd)') (r(unique))  (e(N))
	
}
}
frame change homelessDiDannual 

replace outcome="ESHU" if outcome=="shelter"
replace outcome="HOME" if outcome=="apphomeless"

saveold "${Inputs}/NY_homelessness_did.dta", replace
frame change default





********************************
********* DiD - CREDIT *********
******************************** 
 
*** Set Fixed Effects and Clustering
global fe "caseid time index"
global clusvar "partyr caseid"

*** Symmetric DiD
capture frame drop creditDIDtable
frame create creditDIDtable str55 spec str55 outcome  str32 time str32 refperiod beta se persons N 

foreach spec in all  {
	foreach out in zerorevolving creditscore autoloan deliquency finindex {

	reghdfe `out' evictionorderq12 evictionorderq11 evictionorderq10 evictionorderq9 evictionorderq8 evictionorderq7 evictionorderq6 evictionorderq5 evictionorderq1q4 evictionorderq0  levictionorderq5 levictionorderq6 levictionorderq7 levictionorderq8 levictionorderq9	levictionorderq10	levictionorderq11	levictionorderq12	 if (index>=-12 & index<=12 ) & `spec'==1, absorb($fe )  cluster($clusvar)

	frame post creditDIDtable ("`spec'") ("`out'") ("Q01Q04") ("symdid") (_b[evictionorderq1q4]) (_se[evictionorderq1q4])  (e(df_a_nested)) (e(N))
	
	reghdfe `out' evictionorderq12 evictionorderq11 evictionorderq10 evictionorderq9 evictionorderq8 evictionorderq7 evictionorderq6 evictionorderq5q8 evictionorderq1q4 evictionorderq0 levictionorderq1 levictionorderq2 levictionorderq3 levictionorderq4  levictionorderq9	levictionorderq10	levictionorderq11	levictionorderq12	 if (index>=-12 & index<=12 ) & `spec'==1, absorb($fe )  cluster($clusvar)

	frame post creditDIDtable ("`spec'") ("`out'") ("Q05Q08") ("symdid") (_b[evictionorderq5q8]) (_se[evictionorderq5q8])  (e(df_a_nested)) (e(N))
	
}
} 
 
frame change creditDIDtable

replace outcome="credit" if outcome=="creditscore"
replace outcome="zero_rev" if outcome=="zerorevolving"
replace outcome="auto" if outcome=="autoloan"
replace outcome="delin_acc_bal" if outcome=="deliquency"
replace outcome="finindex" if outcome=="finindex"

rename spec group 
rename refperiod specification

frame creditDIDtable: save  "${Inputs}\NY_credit_did.dta", replace
 
 

********************************
********* DiD - MOVES **********
******************************** 
 
*** Set Fixed Effects and Clustering
global fe "caseid yearsince year"
global clusvar "partyr caseid"

**** REG Results
capture frame drop movesDIDannual
frame create movesDIDannual str55 spec str25 group  str55 outcome  str32 time beta se N

foreach g in all black notblack female male {
	foreach out in diffadd  {

	**************
	reghdfe `out' evictionorder6 evictionorder5 evictionorder4 evictionorder3 evictionorder2 evictionorder1 evictionorder0  levictionorder2 levictionorder3 levictionorder4  if all==1 & ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)
	frame post movesDIDannual  ("did") ("`g'") ("`out'")  ("Q01Q04")  (_b[evictionorder1]) (_se[evictionorder1]) (e(N))

	unique caseid if evictionorder==0 & ivsample==1 & yearsince==1
	local casepesr `r(unique)'
	
	sum `out' if evictionorder==0 & e(sample)==1 & yearsince==1
	capture frame post movesDIDannual ("meansd") ("`g'") ("`out'")   ("Q01Q04")   (`=r(mean)') (`=r(sd)') (`=r(N)'')

	**************
	reghdfe `out' evictionorder6 evictionorder5 evictionorder4 evictionorder3 evictionorder2 evictionorder1 evictionorder0  levictionorder1 levictionorder3 levictionorder4  if all==1 & ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)
	frame post movesDIDannual  ("did") ("`g'") ("`out'")  ("Q05Q08")  (_b[evictionorder2]) (_se[evictionorder2]) (e(N))

	unique caseid if evictionorder==0 & ivsample==1 & yearsince==2
	local casepesr `r(unique)'
	
	sum `out' if evictionorder==0 & e(sample)==1 & yearsince==2
	capture frame post movesDIDannual ("meansd") ("`g'") ("`out'")   ("Q05Q08")   (`=r(mean)') (`=r(sd)') (`=r(N)'')
}
}

frame movesDIDannual: replace out="Not at Eviction Address" if spec!="moveq"
frame movesDIDannual: save "${Inputs}/NY_moves_did.dta", replace
 

 

********************************
********** DiD - Hosp **********
********************************

*** Set Fixed Effects and Clustering
global fe "caseid yearsince year"
global clusvar "partyr caseid"

capture frame drop healthDiDannual
frame create healthDiDannual str55 outcome str32 group str32 time beta se person N 

foreach g in everyone {
foreach o in numED numnonpreg num_anymental {
			
			reghdfe `o' evictionorder6 evictionorder5 evictionorder4 evictionorder3 evictionordery2 evictionorder1 evictionorder0 levictionorder2 levictionorder3 levictionorder4 if  ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)
	unique caseid if e(sample)==1
	frame post healthDiDannual ("`o'") ("`g'") ("Q01Q04")  (_b[evictionorder1]) (_se[evictionorder1]) (r(unique)) (e(N))

				reghdfe `o' evictionorder6 evictionorder5 evictionorder4 evictionorder3 evictionorder2 evictionorder1 evictionorder0 levictionorder1  levictionorder3 levictionorder4 if  ivsample==1 & `g'==1 , absorb($fe)  cluster($clusvar)
	unique caseid if e(sample)==1
	frame post healthDiDannual ("`o'") ("`g'") ("Q05Q08")  (_b[evictionorder2]) (_se[evictionorder2]) (r(unique)) (e(N))
	
}
}
frame change healthDiDannual

gen label=""
replace label="Num Hospital Visits" if regexm(outcome, "numnonpreg")==1
replace label="Num Emergency Visits" if regexm(outcome, "numED")==1
replace label="Num Mental Health" if regexm(outcome, "num_anymental")==1

drop if label==""
replace group="all" if group=="everyone"
order label time group bet se person N 
drop outcome
saveold "${Inputs}/NY_hospital_did.dta", replace
